#pragma once
#ifndef SYPX_GUICOMPONENT
#define SYPX_GUICOMPONENT

#include "Base.h"

//Disable Mem-Check
#ifdef SYPX_MEMCHECK
#include "nommgr.h"
#endif

#ifdef SYPX_PLATFORM_IPHONE
#include <tr1/functional>
#else
#include <functional>
#endif

//Enable Mem-Check after standard library
#ifdef SYPX_MEMCHECK
#include "mmgr.h"
#endif

#include "Base.h"
#include "Mesh.h"
#include "Event.h"

#define SYPXBIND std::bind
#define SYPX_ARG1 std::placeholders::_1
#define SYPX_ARG2 std::placeholders::_2

namespace SypX
{
	class Texture;
	class GuiComponent;

	typedef std::function<void ( GuiComponent*, Event& )> GuiCallBack;

	class SYPXAPI GuiComponent : public Mesh
	{
	public:
		GuiComponent(float w, float h);
		virtual ~GuiComponent(void);
		///Returns the Mesh Instance for this GuiComponent
		MeshInstance* getMeshInstance();
		///Sets the texture which this GuiComponent should use
		void setTexture(Texture* t);
		///Draws the GuiComponent
		virtual void draw()=0;

		bool withinBounds(float x, float y);
		///onDown call back
		GuiCallBack onDownCallBack;
		///onUp call back
		GuiCallBack onUpCallBack;
		///onIn call back
		GuiCallBack onInCallBack;
		///onOut call back
		GuiCallBack onOutCallBack;
		///global onDown logic for ALL GuiComponents
		virtual void onDown( Event& e );
		///global onUp logic for ALL GuiComponents
		virtual void onUp( Event& e );
		///global onIn logic for ALL GuiComponents
		virtual void onIn( Event& e );
		///global onOut logic for ALL GuiComponents
		virtual void onOut( Event& e );
		///Main Input processing method which triggers input event handlers(onUp, onDown, etc..) Returns true when action taken
		virtual bool processInput(Event& e);
		///move
		void move(float x, float y);
		///default action
		void doNothing(GuiComponent*, Event& e);
	protected:
        Texture* tex;
        ///Check bounds
		float width, height;
		///Defines whether the touch/mouse was within bounds in previous frame
		bool wasIn;

		MeshInstance* mi;
	};

}
#endif
